{
 "cells": [
  {
   "cell_type": "markdown",
   "id": "b9f599ca",
   "metadata": {},
   "source": [
    "# P81练习"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 34,
   "id": "19f5d098",
   "metadata": {},
   "outputs": [],
   "source": [
    "phrase = \"Don't panic!\" # 这是一个字符串"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 35,
   "id": "f4ad190d",
   "metadata": {},
   "outputs": [],
   "source": [
    "plist = list(phrase) "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 36,
   "id": "54fa7d32",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Don't panic!\n"
     ]
    }
   ],
   "source": [
    "print(phrase) # 输出字符串"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 37,
   "id": "124b7e25",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "['D', 'o', 'n', \"'\", 't', ' ', 'p', 'a', 'n', 'i', 'c', '!']\n"
     ]
    }
   ],
   "source": [
    "print(plist) # 输出列表"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 38,
   "id": "457701f9",
   "metadata": {},
   "outputs": [],
   "source": [
    "new_phrase = ''.join(plist[1:3]) # 新的字符串从列表中取出第一个到第三个（第三个不取），即“on” # 小教训:报错原因是join前面少了一个\".\""
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 39,
   "id": "67d5b3a4",
   "metadata": {},
   "outputs": [],
   "source": [
    "new_phrase = new_phrase+''.join([plist[5],plist[4],plist[7],plist[6]]) # 新的字符串+列表的第6，5，8，7位（从左到右的顺序）"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 40,
   "id": "54a15476",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "['D', 'o', 'n', \"'\", 't', ' ', 'p', 'a', 'n', 'i', 'c', '!']\n"
     ]
    }
   ],
   "source": [
    "print(plist) # 输出列表元素"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 41,
   "id": "3e62b1aa",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "on tap\n"
     ]
    }
   ],
   "source": [
    "print(new_phrase) # 输出新字符串"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3 (ipykernel)",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.9.12"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
